<template>
  <div class="">
    <div class="page-filter mb10 fl">
      <el-form ref="filter" :model="filter" label-width="0">
        <el-form-item class="mr10 mb5 fl">
          <VerifyType v-model="filter.approve_key" />
        </el-form-item>
        <el-form-item class="mr10 mb5 fl">
          <StaffSelect v-model="filter.approve_user" />
        </el-form-item>
        <el-form-item class="mr10 mb5 fl">
          <el-input v-model="filter.forms" placeholder="描述" size="small" clearable />
        </el-form-item>
        <el-form-item class="mr10 mb5 fl" style="width: 300px">
          <el-button size="small" @click="app.resetFields($refs['filter'].$parent,'filter')">清 空</el-button>
          <el-button type="primary" size="small" @click="getList">查 询</el-button>
        </el-form-item>
      </el-form>
    </div>
    <el-table v-loading="app.loading" class="search-table" :data="list" border fit highlight-current-row style="width: 100%;">
      <el-table-column label="序号" align="center" width="56px">
        <template slot-scope="{$index}">
          {{ $index + 1 }}
        </template>
      </el-table-column>
      <el-table-column label="申请人" width="120px" prop="nickname" />
      <el-table-column label="审批类型" width="120px" prop="value" />
      <el-table-column label="状态" align="center" width="90px" :formatter="states" />
      <el-table-column label="申请时间" align="center" width="140" prop="create_time" />
      <el-table-column label="描述" min-width="260px">
        <template slot-scope="scope">
          <span v-html="des(scope.row)" />
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" width="90px" fixed="right">
        <template slot-scope="{row}">
          <el-dropdown>
            <el-button type="primary" size="mini">
              操作<i class="el-icon-arrow-down el-icon--right" />
            </el-button>
            <el-dropdown-menu slot="dropdown">
              <el-dropdown-item @click.native="handleDialog({...row, ...{dTitle: '我的审批', dType: 'view', dField: dField}})">详 情</el-dropdown-item>
            </el-dropdown-menu>
          </el-dropdown>
        </template>
      </el-table-column>
    </el-table>
    <pagination
      v-show="filter.pageAll>0"
      :total="filter.pageAll"
      :page.sync="filter.pageCurrent"
      :limit.sync="filter.pageNumber"
      @pagination="getList"
    />
    <Dialog ref="dialog" :get-data="getList" :info="dialog" />
  </div>
</template>

<script>
import { ccs } from '@/api/approval/approve'
import Dialog from './components/verify-dialog'
import VerifyType from '@/myComponents/VerifyType'
import StaffSelect from '@/myComponents/StaffSelect'
import page from '@/utils/page'

export default {
  name: '',
  components: { VerifyType, Dialog, StaffSelect },
  extends: page,
  props: {
    reqList: {
      default: ccs,
      type: Function
    }
  },
  data() {
    return {
      dField: ['id', 'lap_id', 'nickname', 'value', 'approve_key', 'su_id', 'des', 'forms', 'files', 'tables', 'state', 'lpai_state', 'lpai_id', 'reason', 'create_time']
    }
  },
  created() {
    this.getList()
  },
  methods: {
    states(e) {
      let s = ''
      switch (e.state) {
        case 0:
          s = '已驳回'
          break
        case 1:
          s = '已通过'
          break
        case 2:
          s = '进行中'
          break
        case 3:
          s = '已撤销'
          break
        default:
          break
      }
      return s
    },
    des(e) {
      if (e.forms) {
        try {
          const forms = JSON.parse(e.forms)
          let sd = ''
          const len = forms.length
          for (let i = 0; i < len; i++) {
            sd += forms[i].t + ': ' + forms[i].v + '<br/>'
          }
          return sd
        } catch (error) {
          return e.des
        }
      } else {
        return e.des
      }
    }
  }
}
</script>
